Perform interventions and counterfactuals, using Bayesian networks as causal models.
# network transformations used in causal inference.
mutilated(x, evidence)
twin(x)# causal inference types.
intervention(x, evidence)
counterfactual(x, evidence, merging = TRUE)
A bn, bn.fit or scm object, depending on the class of
x.
Objects returned by twin() will additionally have class bn.twin
(if x is a bn or bn.fit object) or scm.twin (if
x is an scm object).
Objects returned by counterfactual() will additionally have classes
bn.twin and bn.ctf (if x is a bn or bn.fit
object) or scm.twin (if x is an scm object).
an object of class bn, bn.fit or scm.
a list, in the same format as the evidence for likelihood
weighting (see cpquery).
a boolean value. If TRUE, the twin network is reduced
by node merging after introducing the counterfactual.
Marco Scutari
mutilated() constructs the mutilated network arising from an ideal
intervention setting the nodes involved to the values specified by
evidence.
twin() constructs the twin network required to compute counterfactuals,
separating noise (exogenous) from functional (factual) nodes and adding
counterfactual nodes.
intervention() is an alias of mutilated().
counterfactual() constructs the twin network and introduces a
counterfactual (that is, an intervention on the counterfactual nodes) before
applying node merging (optional). The intervention in evidence is
specified using the labels of the nodes in x, and is then applied to
the corresponding counterfactual nodes.
Both twin() and counterfactual() label nodes as follows:
A counterfactual node has the label of the corresponding factual node
with a period appended (as in paste0(label, ".")).
A noise node has the label of the corresponding factual node with a
"u" prepended (as in paste0("u", label)).
Evidence in intervention() can reference factual and counterfactual
nodes. Evidence in counterfactual() can only reference counterfactual
nodes; factual nodes will be replaced by the corresponding counterfactual
nodes with a warning. Referencing exogenous nodes in either function will
produce an error.
Balke A, Pearl J (2022). "Probabilistic Evaluation of Counterfactual Queries." Probabilistic and Causal Inference: The Works of Judea Pearl, 237--254. The original is in the Proceedings of AAAI, 1994.
Graham D, Lee CM, Perov Y (2019). "Copy, Paste, Infer: A Robust Analysis of Twin Networks for Counterfactual Inference." NeurIPS19 CausalML workshop.
Koller D, Friedman N (2009). Probabilistic Graphical Models: Principles and Techniques. MIT Press.
Shpitser I, PearlJ (2007). "What counterfactuals can be tested." Proceedings of the 23rd Conference on Uncertainty in Artificial Intelligence (UAI), 352--359.
# example from Graham, Lee and Perov.
dag = model2network("[C][A|C][B|C][D|A:B]")
intervention(dag, evidence = list(A = 0))
twin(dag)
counterfactual(dag, evidence = list(A. = 0), merging = FALSE)
counterfactual(dag, evidence = list(A. = 0), merging = TRUE)
Run the code above in your browser using DataLab